#{extends 'admin.html' /}
#{set title:'Administration : Ajout d\'un utilisateurs' /}
#{if flash.error}
    <h4 class="alert_error">${flash.error}</h4>
#{/if}
<article class="module width_full">
    <header><h3 class="tabs_involved">Ajouter un Utilisateur</h3>
        <ul class="tabs">
            <li><a href="@{Admin.index}">Annuler</a></li>
        </ul>

    </header>

    <div class="entity">
        #{form @Users.save(), id:'createForm'}
        <div class="module_content">
            <fieldset>
                <label>Prénom : </label>
                <input type="text" name="entity.firstname" value="${entity?.firstname}"/>
                <span class="error">${errors.forKey('entity.firstname')}</span>
            </fieldset>
            <fieldset>
                <label>Nom : </label>
                <input type="text" name="entity.lastname" value="${entity?.lastname}"/>
                <span class="error">${errors.forKey('entity.lastname')}</span>
            </fieldset>
            <fieldset>
                <label>Date de Naissance : </label>
                #{if entity.birthday != null}
                <input id="birthday" type="date" name="entity.birthday" 
                       value="${entity?.birthday.format('dd/MM/yyyy')}"
                       size="10" />
                #{/if}
                #{else}
                <input id="birthday" type="date" name="entity.birthday" 
                       value="${entity?.birthday}"
                       size="10" />
                #{/else}
                <span class="error">${errors.forKey('entity.birthday')}</span><span>Sous la Forme : jj/mm/aaaa</span>
            </fieldset>
            <fieldset>
                <label>Avatar : </label>
                <input type="text" name="entity.avatar" value="${entity?.avatar}"/>
                <span class="error">${errors.forKey('entity.avatar')}</span>
            </fieldset>
            <fieldset>
                <label>Adresse : </label>
                <input type="text" name="entity.adress" value="${entity?.adress}"/>
                <span class="error">${errors.forKey('entity.adress')}</span>
            </fieldset>
            <fieldset>
                <label>N° de Téléphone : </label>
                <input type="text" name="entity.phonenumber" value="${entity?.phonenumber}"/>
                <span class="error">${errors.forKey('entity.phonenumber')}</span>
            </fieldset>
            <fieldset>
                <label>Courrier Electronique : </label>
                <input type="text" name="entity.email" value="${entity?.email}"/>
                <span class="error">${errors.forKey('entity.email')}</span>
            </fieldset>
            <fieldset>
                <label>Nom d'utilisateur : </label>
                <input type="text" name="entity.username" value="${entity?.username}"/>
                <span class="error">${errors.forKey('entity.username')}</span>
            </fieldset>
            <fieldset>
                <label>Mot de Passe : </label>
                <input type="password" name="entity.password" value="${entity?.password}"/>
                <span class="error">${errors.forKey('entity.password')}</span>
            </fieldset>
            <fieldset>
                <label>Groupe : </label>
                <select name="entity.groups.id">
                          
              
        %{ models.Group.all().fetch().sort{ it.toString() }.each() { }%
          
          %{
            selected = false;
            if (entity?.groups?.id == it.id) {
              selected = true
            }
          }%
          <option value="${it?.id}" ${selected ? 'selected'.raw() : ''}>${it}</option>
        %{ } }%
        </select>
                <span class="error">${errors.forKey('entity.groups')}</span>
            </fieldset>
        
        </div>
        <footer>
            <div class="submit_link">
                <input type="submit" name="submit" value="Créer !" class="alt_btn"/>
            </div>
        </footer>
        #{/form}
    </div>
</article>
